/** 奖品类
 *
 */
export default class Lottery {
  private readonly peoples: string[];
  private readonly n: number;
  private result: string[];
  constructor(peoples: string[], lotteryCount: number) {
    this.peoples = peoples;
    this.n = lotteryCount;
    this.result = [];
  }

  /**开始抽奖
   *
   */
  start(): void {
    if (this.n > this.peoples.length) {
      throw new Error("奖品数量大于抽奖人数!!");
    }

    for (let i = 0; i < this.n; i++) {
      const index = Math.floor(Math.random() * this.peoples.length);
      this.result.push(this.peoples[index]);
      this.peoples.splice(index, 1);
    }
  }

  /**获取抽奖结果
   *
   * @returns
   */
  getResult() {
    return `中奖人：${this.result.toString()}`;
  }
}
